In many computer graphics applications it is either necessary or convenient to employ floating-point numbers during the process of computing pixel values, wherein a pixel is a picture element that is a smallest displayable unit of an image. That is, for some applications the additional precision inherent in a floating-point representation is desirable, or the convenience of the automatic scaling of a floating-point representation makes the programming and/or computation of pixel values more efficient.
One such application is known as ray-tracing, where many small effects (e.g. multiple reflections and multiple light sources) must be accumulated for each pixel. Another application where a floating-point pixel representation is advantageous is volume rendering, where each layer of a volume may make a contribution to a pixel value, and many such small contributions must be accumulated.
However, when displaying the resulting pixel values the floating-point values must, typically, be converted to one-byte values in that most display devices operate with one-byte pixel values. Typically, three such one-byte values are used for each pixel, one for each of the primary colors (red, green, and blue).
The process of converting the floating-point values to one-byte values includes a number of steps which, when taken together, are time consuming and often decrease the efficiency of the system. Typically, these steps include the following.
Scaling of pixel values: For example, the floating-point pixel values may be, by convention, in the range from 0.0 to 1.0; but the one-byte pixel values are, by definition, in the range from 0 to 255. As a result, multiplication of the floating-point pixel values by 255 is required. However, a floating-point multiplication can be a relatively time-consuming operation. Furthermore, the use of hardware multipliers increases the cost, complexity, and power consumption of the system.
Range limiting: In that the range of floating-point numbers is very large compared to the range of one-byte values, at times a floating-point pixel value is found to be outside of the range of byte values. For example, using the assumption of the preceding paragraph that the floating-point values are to be scaled by 255, a floating-point pixel value of, for example, 1.01 would be converted to an integer value of 257. However, 257 cannot be represented as a one-byte value, and must be represented instead by the maximum possible one-byte value, 255. Similarly, floating-point pixel values of less than zero must be represented by a byte pixel value of 0. Range limiting is typically accomplished by two comparisons (one comparison with the minimum value and one comparison with the maximum value) and with conditional branches. However, conditional branches are relatively time-consuming operations in modern data processors in that they interrupt the flow of processor pipelines.
Gamma correction: Most computer displays exhibit a non-linear relationship between pixel values and screen brightness, typically of the form EQU brightness=(pixel value).sup.gamma,
where "gamma" is a number that is characteristic of a particular display monitor. To compensate for this effect, it is desirable to use a pixel value computed according to the formula EQU pixel value=(desired brightness).sup.(1/gamma).
Generally the floating-point pixel value described above is taken to represent the desired brightness. However, the required exponentiation operation is a computationally expensive process.
A final pixel operation is the required conversion from the floating-point representation to an integer representation prior to display of the pixel.
Thus, for this example the operations required to convert a floating-point pixel value to a byte pixel value are as follows (expressed in the C programming language):
float in; PA1 unsigned char out; PA1 if (in&lt;0) out=0; /* Range Limiting */ PA1 else if (in&gt;1.0) out=255; /* Range Limiting */ PA1 else out=255.0 * pow(in, 1.0/gamma); /* Scaling and Gamma correction */
It is noted that the conversion from floating-point to integer is implicit in the "else out" assignment.
In this example, even if the gamma correction is omitted, the resulting calculation still requires a considerable amount of processing time for each pixel. In that a typical display screen may display several hundreds of thousands or millions of pixels, each having a red, green, and blue constituent, it can be realized that a considerable amount of processing effort may be expended to generate but one displayable image frame.
It is thus an object of this invention to provide an efficient method for converting a floating-point pixel representation into a displayable integer pixel representation.
It is a further object of this invention to provide an efficient technique for performing at least one operation on a pixel that is expressed in a floating-point representation, and to provide as a result of the operation an integer representation of the pixel.